package com.akcome.apollo.service.impl;

import java.util.Locale;
import java.util.Map;

import javax.mail.internet.MimeMessage;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;

import com.akcome.apollo.domain.enums.MsgTemplateEnum;
import com.akcome.apollo.service.MailService;


@Service
public class MailServiceImpl implements MailService {

	@Autowired
	private JavaMailSender mailSender;
	
	
	@Value("${spring.mail.username}")
	private String FROM;
	
	@Autowired
	private TemplateEngine templateEngine;
	
	private Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Override
	public void mailSender(String to,MsgTemplateEnum msgTemplate,Map<String, Object> model,Locale locale) throws Exception{
		logger.error("发送"+msgTemplate.getDesc()+"邮件："+to);
		for (String key : model.keySet()) {
			logger.error(key+":"+model.get(key));
		}
		
		/*//模板邮件
		MimeMessage mimeMessage = mailSender.createMimeMessage();

		MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
		
		helper.setFrom(FROM);//发送者.
		helper.setTo(to);//接收者.
		helper.setSubject(msgTemplate.getDesc());//邮件主题.
		
		Context context = new Context();
		context.setVariables(model);
		context.setLocale(locale);
        String html = templateEngine.process(msgTemplate.getName(), context);
        helper.setText(html, true);
        mailSender.send(mimeMessage);*/
	}
}
